using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security.Principal;
using System.Text;
using System.Web;
using Sedna.Domain;

namespace Sedna.Core.Security
{
    public class SednaWorkPrincipal : GenericPrincipal, ICloneable
    {
        private IUser user;
        private string[] roleSave;
        private CultureInfo culture;
        
        public IUser User
        {
            get { return user; }
            set { user = value;}
        }

        public CultureInfo Culture
        {
            get { return culture;}
            set { culture = value;}
        }
                
        public SednaWorkPrincipal(IIdentity identity, string[] roles, IUser user) : base(identity, roles)
        {
            if (user == null)
                throw new InvalidDataException("Not logged in.");
            roleSave = roles;
            this.user = user;            
        }
        
        public SednaWorkPrincipal(IIdentity identity, string[] roles) : base(identity, roles)
        {
            roleSave = roles;
        }
                
        /*public SednaCookiePrincipal getCookiePrincipal()
        {
            if (UserMapper.GetUser()==null)
                UserMapper.AddUser(user);
            return new SednaCookiePrincipal(Identity,roleSave);
        }*/
        
        /*public static SednaWorkPrincipal Restore()
        {
            return UserMapper.RestoreCurrentState();
        }*/

        public object Clone()
        {
//            User newUser = (User) user.Clone();
//            if (user.Customer != null)
//                newUser.SetCustomer((Customer)user.Customer.Clone());
            SednaWorkPrincipal newPrincipal = new SednaWorkPrincipal(Identity,roleSave);
            newPrincipal.culture = culture;
            return newPrincipal;
        }
    }
}
